﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization.Substituters {

    public class SubstituterEnFlip extends SubstituterSimple {

        protected static const OPEN_BRACE_CODE:Number = "{".charCodeAt(0);
        protected static const CLOSE_BRACE_CODE:Number = "}".charCodeAt(0);

        protected static var flipMap:Object = {
            v:"ʌ",
            k:"ʞ",
            !:"¡",
            w:"ʍ",
            l:"ן",
            a:"ɐ",
            ":"„",
            m:"ɯ",
            b:"q",
            .:"˙",
            y:"ʎ",
            n:"u",
            c:"ɔ",
            d:"p",
            ;:"؛",
            [:"]",
            e:"ǝ",
            ':",",
            <:">",
            f:"ɟ",
            ,:"'",
            r:"ɹ",
            g:"ƃ",
            (:")",
            h:"ɥ",
            _:"‾",
            ?:"¿",
            t:"ʇ",
            i:"ı",
            j:"ɾ"
        };

        protected static function flipString(_arg1:String):String{
            var _local6:String;
            var _local2:int = _arg1.length;
            var _local3:Array = [];
            var _local4:Boolean;
            var _local5:int;
            while (_local5 < _local2) {
                _local6 = _arg1.charAt(_local5);
                if (((_local4) || ((_local6.charCodeAt(0) == OPEN_BRACE_CODE)))){
                    _local3.push(_local6);
                    _local4 = !((_local6.charCodeAt(0) == CLOSE_BRACE_CODE));
                } else {
                    _local3.push(flipChar(_local6));
                };
                _local5++;
            };
            return (_local3.join(""));
        }
        protected static function reverse(_arg1:String):String{
            var _local2 = "";
            var _local3:int = (_arg1.length - 1);
            while (_local3 >= 0) {
                _local2 = (_local2 + _arg1.charAt(_local3));
                _local3--;
            };
            return (_local2);
        }
        protected static function flipChar(_arg1:String):String{
            if (flipMap.hasOwnProperty(_arg1)){
                return (flipMap[_arg1]);
            };
            return (_arg1);
        }

        override public function replace(_arg1:String, _arg2:Object):String{
            var _local3:String;
            _arg1 = flipString(_arg1);
            for (_local3 in _arg2) {
                _arg2[_local3] = flipString(_arg2[_local3]);
            };
            _arg1 = super.replace(_arg1, _arg2);
            return (reverse(_arg1));
        }

    }
}//package ZLocalization.Substituters 
